<template>
  <!-- 通知 -->
  <el-dialog
    v-model="props.modelValue"
    width="1260px"
    :show-close="false"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <!-- <template #header="{ close, titleId, titleClass }">
      <div class="my-header">
        <h4
          :id="titleId"
          :class="titleClass"
        >
          {{ t('notification') }}
        </h4>
        <img
          src="@/assets/img/icon_guanbi.png"
          @click="close"
          class="close"
        />
      </div>
    </template> -->

    <div class="tit">{{ t('externalAssistance.step4page.t1') }}</div>
    <div class="bg info mt-2 flexsc">{{ store.orderInfo.orderNo }} {{ store.orderInfo.assistOrderName }}</div>
    <div class="bg attr flexsc">
      <div class="mr-8">
        <span>{{ t('founder') }}:</span>
        <span>{{ store.orderInfo.createByName }}</span>
      </div>
      <div class="mr-8">
        <span>{{ t('createTime') }}:</span>
        <span>{{ dateFormat(store.orderInfo.createTime) }}</span>
      </div>
      <div>
        <span>{{ t('updateTime') }}:</span>
        <span>{{ dateFormat(store.orderInfo.updateTime) }}</span>
      </div>
    </div>

    <div class="tit mt-6">{{ t('procurement.step4page.t2') }}</div>
    <div class="list mt-2">
      <div
        class="item flexsc"
        v-for="item in store.inquiryParams.providerList"
      >
        <div class="left">
          <img
            :src="item.enterpriseLogo"
            alt=""
          />
        </div>
        <div class="right">
          <div class="flexsb">
            <div class="tit">
              <div>{{ item.enterpriseName }}</div>
              <div v-if="locale === 'zh-CN'">{{ item.enterpriseNameCn }}</div>
            </div>
          </div>
          <div class="rate">
            <template v-for="n in 5">
              <img
                src="@/assets/img/icon_shoucang_pre.png"
                alt=""
                v-if="n <= item.ratingStar"
              />
              <img
                src="@/assets/img/icon_shoucang_nor.png"
                alt=""
                v-else
              />
            </template>
          </div>
          <div class="from">{{ item.country }}{{ item.area }}{{ item.address }}</div>
        </div>
      </div>
    </div>

    <template #footer>
      <div class="dialog-footer flexcc">
        <el-button
          color="#252628"
          plain
          @click="cancel"
        >
          {{ t('cancelText') }}
        </el-button>
        <el-button
          type="primary"
          color="#252628"
          @click="confirm"
        >
          {{ t('dockRepair.step4page.confirm') }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import useExternalAssistance from '@/stores/externalAssistance.js'
import useLogin from '@/stores/login'
import { invitationToQuoteApi } from '@/service/externalAssistance'
import { dateFormat } from '@/utils'

const { t, locale } = useI18n()

const router = useRouter()
const route = useRoute()
const storeLogin = useLogin()

const store = useExternalAssistance()
const { reset } = store

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['update:modelValue'])

const handleClose = () => {
  emit('update:modelValue', false)
}

const cancel = () => {
  handleClose()
}

//
const confirm = () => {
  const params = {
    ...store.inquiryParams,
    providerList: store.inquiryParams.providerList.map((item) => item.id),
    id: store.orderInfo.id
  }

  invitationToQuoteApi(params).then(({ msg }) => {
    ElMessage.success(msg)
    reset()
    router.push('/user/externalAssistance')
  })
}
</script>

<style scoped lang="scss">
.bg {
  padding: 29px;
  background: #f5f5f5;
}
.info {
  font-weight: bold;
}
.attr {
  border-top: 1px solid #eaebec;
  div {
    span:last-of-type {
      margin-left: 5px;
      color: #252628;
    }
  }
}
.tit {
  font-weight: bold;
  font-size: 16px;
  color: #252628;
}
.list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 50px;
  row-gap: 20px;
  > .item {
    background: #fff;
    padding: 30px;
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 22px;
    border: 1px solid #eaebec;
    transition: 0.3s;
    padding: 14px;
    .left {
      width: 100%;
      height: 120px;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    .right {
      height: 120px;
      display: grid;
      grid-template-rows: auto;
      gap: 15px;
      align-content: center;

      .tit {
        transition: 0.3s;
      }

      .from {
        color: #9d9fa5;
        font-size: 12px;
        text-transform: uppercase;
      }

      .rate {
        img {
          margin-right: 5px;
        }
      }
    }
  }
}
</style>
